package com.ruoyi.app.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.app.domain.BasicProfession;
import com.ruoyi.app.service.IBasicProfessionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 行业分类Controller
 * 
 * @author ruoyi
 * @date 2023-12-21
 */
@Api(value = "行业分类", tags = "行业分类")
@RestController
@RequestMapping("/basic/profession")
public class BasicProfessionController extends BaseController
{
    @Autowired
    private IBasicProfessionService basicProfessionService;

    /**
     * 查询行业分类列表
     */
    @PreAuthorize("@ss.hasPermi('basic:profession:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicProfession basicProfession)
    {
        startPage();
        List<BasicProfession> list = basicProfessionService.selectBasicProfessionList(basicProfession);
        return getDataTable(list);
    }

    /**
     * 导出行业分类列表
     */
    @PreAuthorize("@ss.hasPermi('basic:profession:export')")
    @Log(title = "行业分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicProfession basicProfession)
    {
        List<BasicProfession> list = basicProfessionService.selectBasicProfessionList(basicProfession);
        ExcelUtil<BasicProfession> util = new ExcelUtil<BasicProfession>(BasicProfession.class);
        util.exportExcel(response, list, "行业分类数据");
    }

    /**
     * 获取行业分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:profession:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(basicProfessionService.selectBasicProfessionById(id));
    }

    /**
     * 新增行业分类
     */
//    @PreAuthorize("@ss.hasPermi('basic:profession:add')")
    @ApiOperation("添加行业")
    @Log(title = "行业分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BasicProfession basicProfession)
    {
        return toAjax(basicProfessionService.save(basicProfession));
    }

    /**
     * 修改行业分类
     */
//    @PreAuthorize("@ss.hasPermi('basic:profession:edit')")
    @ApiOperation("修改分类")
    @Log(title = "行业分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BasicProfession basicProfession)
    {
        return toAjax(basicProfessionService.updateById(basicProfession));
    }

    /**
     * 删除行业分类
     */
//    @PreAuthorize("@ss.hasPermi('basic:profession:remove')")
    @ApiOperation("删除分类")
    @Log(title = "行业分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        List<String> objects = Arrays.asList(ids);
        return toAjax(basicProfessionService.removeByIds(objects));
    }

    @ApiOperation("获取分类列表")
    @GetMapping("/getList")
    public AjaxResult getList(BasicProfession basicProfession)
    {
        List<BasicProfession> list = basicProfessionService.selectBasicProfessionList(basicProfession);
        return success(list);
    }
}
